

namespace SharpSoft.OS
{
    using System;
    using System.IO;
    using System.Text;
    using Newtonsoft.Json.Linq;
    using System.Collections.Generic;
    public class os
    {
        public static string shell(string cmd, bool waitresult = true)
        {
            string result = "";
            using (System.Diagnostics.Process proc = new System.Diagnostics.Process())
            {
                proc.StartInfo.FileName = "/bin/bash";
                proc.StartInfo.Arguments = "-c \" " + cmd + " \"";
                proc.StartInfo.UseShellExecute = false;
                proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.RedirectStandardError = true;
                proc.Start();

                result += proc.StandardOutput.ReadToEnd();
                result += proc.StandardError.ReadToEnd();

                if (waitresult)
                {
                    proc.WaitForExit();
                }
            }
            return result;
        }

        public static FileStream fopen(string path)
        {
            var fs = new FileStream("/proc/version", FileMode.Open);
            return fs;
        }

        public static string fopentext(string path, Encoding encoding = null)
        {
            using (var sr = new StreamReader(fopen(path), encoding ?? Encoding.UTF8))
            {
                return sr.ReadToEnd();
            }
        }
    }
}
